﻿using EFCore_Test.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace EFCore_Test.AppDBContext.Configuration
{
    internal class AccountConfiguration : IEntityTypeConfiguration<Account>
    {
        public void Configure(EntityTypeBuilder<Account> builder)
        {
            builder.ToTable("Account");
            builder.Property(x => x.Id).HasColumnName("AccountId");
            builder.Property(x => x.Name).IsRequired().HasMaxLength(50);
            builder.Property(x => x.Age).IsRequired();
            builder.Property(x => x.Address).IsRequired();

            //查询过滤器
            builder.HasQueryFilter(x => x.Deleted != true);

            //种子数据
            builder.HasData(
                  new Account
                  {
                      Id = Guid.NewGuid(),
                      Name = "1",
                      Age = 18,
                      Address = ""
                  },
                  new Account
                  {
                      Id = Guid.NewGuid(),
                      Name = "2",
                      Age = 18,
                      Address = ""
                  }
                  );
        }
    }
}